package weekMatch.two_106;

public class LeeCode_02 {
    public static void main(String[] args) {
        System.out.println(longestSemiRepetitiveSubstring("52233"));
    }
    private static int longestSemiRepetitiveSubstring(String s) {
        char[] cs = s.toCharArray();
        int n = s.length(), ans = 1;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                if (get(cs, i, j))
                    ans = Math.max(ans, j - i + 1);
            }
        }
        return ans;
    }
    private static boolean get(char[] cs, int l, int r){
        int count = 0;
        for (int i = l + 1; i <= r; i++) {
            if (cs[i] == cs[i - 1])
                count++;
        }
        return count <= 1;
    }
}